package net.lab1024.sa.admin.module.business.test2.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.test2.dao.Test2Dao;
import net.lab1024.sa.admin.module.business.test2.domain.entity.Test2Entity;
import net.lab1024.sa.admin.module.business.test2.domain.form.Test2AddForm;
import net.lab1024.sa.admin.module.business.test2.domain.form.Test2QueryForm;
import net.lab1024.sa.admin.module.business.test2.domain.form.Test2UpdateForm;
import net.lab1024.sa.admin.module.business.test2.domain.vo.Test2VO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

/**
 * 计科院活动信息表 Service
 *
 * @Author mt
 * @Date 2025-07-05 01:56:56
 * @Copyright e
 */

@Service
public class Test2Service {

    @Resource
    private Test2Dao test2Dao;

    /**
     * 分页查询
     */
    public PageResult<Test2VO> queryPage(Test2QueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<Test2VO> list = test2Dao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(Test2AddForm addForm) {
        Test2Entity test2Entity = SmartBeanUtil.copy(addForm, Test2Entity.class);
        test2Dao.insert(test2Entity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(Test2UpdateForm updateForm) {
        Test2Entity test2Entity = SmartBeanUtil.copy(updateForm, Test2Entity.class);
        test2Dao.updateById(test2Entity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Integer> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        test2Dao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Integer id) {
        if (null == id){
            return ResponseDTO.ok();
        }

        test2Dao.deleteById(id);
        return ResponseDTO.ok();
    }
}
